package com.Mt.Controller;

import com.Mt.Dto.Dto;
import com.Mt.Service.MtAddressService;
import com.Mt.Utils.DtoUtil;
import com.Mt.pojo.MtAddress;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("address")
public class MtAddressController {

    @Reference
    private MtAddressService mtAddressService;

    // 根据用户ID查询用户的收货地址
    @GetMapping("selUserId/{userId}")
    public Dto selUserId(@PathVariable String userId){
        return DtoUtil.returnSuccessData(mtAddressService.selUserID(userId));
    }
    // 根据收货地址ID查看详细的信息
    @GetMapping("selId/{id}")
    public Dto selId(@PathVariable int id){
        return DtoUtil.returnSuccessData(mtAddressService.selID(id));
    }
    // 修改地址信息
    @PostMapping("upd")
    public Dto upd(@RequestBody MtAddress mtAddress){
        return DtoUtil.returnSuccessData(mtAddressService.upd(mtAddress));
    }
    // 添加新的地址
    @PostMapping("add")
    public Dto add(@RequestBody MtAddress mtAddress){
        return DtoUtil.returnSuccessData(mtAddressService.add(mtAddress));
    }
}
